History log of /u-boot/cmd/efidebug.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# d678a59d 18-May-2024 Tom Rini <trini@konsulko.com>

Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""

When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing
changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 301bac60 27-Apr-2024 Tom Rini <trini@konsulko.com>

cmd: Remove <common.h> and add needed includes

Remove <common.h> from all "cmd/" files and when needed add
missing include files directly.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 84aab11d 20-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: terminate efidebug test bootmgr early on error

If efi_bootmgr_load() fails, there is no point in trying to start an image
that has not been loaded.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# a55039d6 19-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: superfluous efi_restore_gd after EFI_CALL

EFI_CALL() invokes __efi_entry_check() which executes set_gd(efi_gd).
There is no need to execute set_gd(efi_gd) again via efi_restore_gd().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 102ab672 26-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: in do_efi_capsule_esrt use efi_get_configuration_table

Use library function efi_get_configuration_table() to find the ESRT.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 279b03d9 16-Jan-2024 AKASHI Takahiro <akashi.tkhro@gmail.com>

efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR

At this point, EFI boot manager interfaces is fully independent from
bootefi command. So just rename the configuration parameter.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <kojima.masahisa@socionext.com>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 301bac60 27-Apr-2024 Tom Rini <trini@konsulko.com>

cmd: Remove <common.h> and add needed includes

Remove <common.h> from all "cmd/" files and when needed add
missing include files directly.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 84aab11d 20-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: terminate efidebug test bootmgr early on error

If efi_bootmgr_load() fails, there is no point in trying to start an image
that has not been loaded.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# a55039d6 19-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: superfluous efi_restore_gd after EFI_CALL

EFI_CALL() invokes __efi_entry_check() which executes set_gd(efi_gd).
There is no need to execute set_gd(efi_gd) again via efi_restore_gd().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 102ab672 26-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: in do_efi_capsule_esrt use efi_get_configuration_table

Use library function efi_get_configuration_table() to find the ESRT.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 279b03d9 16-Jan-2024 AKASHI Takahiro <akashi.tkhro@gmail.com>

efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR

At this point, EFI boot manager interfaces is fully independent from
bootefi command. So just rename the configuration parameter.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <kojima.masahisa@socionext.com>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 84aab11d 20-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: terminate efidebug test bootmgr early on error

If efi_bootmgr_load() fails, there is no point in trying to start an image
that has not been loaded.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# a55039d6 19-Apr-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: superfluous efi_restore_gd after EFI_CALL

EFI_CALL() invokes __efi_entry_check() which executes set_gd(efi_gd).
There is no need to execute set_gd(efi_gd) again via efi_restore_gd().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 102ab672 26-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: in do_efi_capsule_esrt use efi_get_configuration_table

Use library function efi_get_configuration_table() to find the ESRT.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 279b03d9 16-Jan-2024 AKASHI Takahiro <akashi.tkhro@gmail.com>

efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR

At this point, EFI boot manager interfaces is fully independent from
bootefi command. So just rename the configuration parameter.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <kojima.masahisa@socionext.com>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <kojima.masahisa@socionext.com>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <akashi.tkhro@gmail.com>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 102ab672 26-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: in do_efi_capsule_esrt use efi_get_configuration_table

Use library function efi_get_configuration_table() to find the ESRT.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 279b03d9 16-Jan-2024 AKASHI Takahiro <takahiro.akashi@linaro.org>

efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR

At this point, EFI boot manager interfaces is fully independent from
bootefi command. So just rename the configuration parameter.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 279b03d9 16-Jan-2024 AKASHI Takahiro <takahiro.akashi@linaro.org>

efi_loader: rename BOOTEFI_BOOTMGR to EFI_BOOTMGR

At this point, EFI boot manager interfaces is fully independent from
bootefi command. So just rename the configuration parameter.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 55125bbf 11-Jan-2024 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: check pointer after memory allocation

After calling efi_alloc() we must check that the return value is not NULL.

Fixes: f01c961ee34c ("cmd: efidebug: add uri device path")
Addresses-Coverity-ID: 477185 Dereference null return value
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f19171c9 08-Jan-2024 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Clean up efi_dp_append and efi_dp_concat

Looking back at the initrd storing functionality, we introduced three
functions, efi_dp_append_or_concatenate(), efi_dp_append/concat(). In
hindsight we could have simplified that by a lot. First of all none of
the functions append anything. They all allocate a new device path and
concatenate the contents of two device paths in one. A boolean parameter
controls the final device path -- if that's true an end node is injected
between the two device paths.

So let's rewrite this and make it a bit easier to read. Get rid of
efi_dp_append(), efi_dp_concat() and rename
efi_dp_append_or_concatenate() to efi_dp_concat(). This is far more
intuitive and the only adjustment that is needed is an extra boolean
argument on all callsites.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 01adf0a4 20-Nov-2023 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: ease efi configuration dependency

Now it is clear that the command actually depends on interfaces,
not "bootefi bootmgr" command.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# f01c961e 09-Nov-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add uri device path

This adds the URI device path option for 'boot add' subcommand.
User can add the URI load option for downloading ISO image file
or EFI application through network. Currently HTTP is only supported.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3616218b 07-Oct-2023 Tom Rini <trini@konsulko.com>

cmd: Convert existing long help messages to the new macro

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0c95744b 28-Jun-2023 Masahisa Kojima <masahisa.kojima@linaro.org>

cmd: efidebug: add missing efi_free_pool for dh subcommand

This adds the missing efi_free_pool call for dh subcommand.

Fixes: a80146205d0a ("cmd: efidebug: add dh command")
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 041840ee 19-Mar-2023 Simon Glass <sjg@chromium.org>

efi: Split out table-listing code into a new file

This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass <sjg@chromium.org>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# eff44401 05-Jan-2023 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: carve out efi_get_memory_map_alloc()

Carve out code from efidebug command used to read the memory map.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3ac026ae 01-Dec-2022 Masahisa Kojima <masahisa.kojima@linaro.org>

efi_loader: utility function to check the variable name is "Boot####"

Some commands need to enumerate the existing UEFI load
option variable("Boot####"). This commit transfers some code
from cmd/efidebug.c to lib/efi_loder/, then exposes
efi_varname_is_load_option() function to check whether
the UEFI variable name is "Boot####".

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 1a127962 29-Nov-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: don't use EFI_LOADER_DATA internally

EFI_LOADER_DATA/CODE is reserved for EFI applications.
Memory allocated by U-Boot for internal usage should be
EFI_BOOT_SERVICES_DATA or _CODE or EFI_RUNTIME_SERVICES_DATA or _CODE.

Reported-by: François-Frédéric Ozog <ff@ozog.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f4d52c41 15-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify efidebug

* don't use EFI_CALL() for variable services
* don't use runtime pointer to access exported function

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f3290be3 04-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify command efidebug

Currently we have subcommands 'efidebug dh' which shows protocols per
handle and 'efidebug devices' which shows the device path. None shows which
U-Boot device matches the handle.

Change 'efidebug dh' to show the device path and the U-Boot device if any
is associated with the handle.

Remove 'efidebug devices'.

Old output of 'efidebug dh':

Handle Protocols
================ ====================
000000001b22e690 Device Path, Block IO
000000001b22e800 Device Path, Block IO, system, Simple File System

New output of 'efidebug dh':

000000001b22e690 (host0)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)
Block IO

000000001b22e800 (host0:1)
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)
Block IO
system
Simple File System

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 80fadf4a 05-Oct-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: simplify do_efi_boot_add()

Use efi_convert_string() to convert a UTF-8 to a UTF-16 string.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 046d7a0b 09-Aug-2022 Michal Simek <michal.simek@amd.com>

cmd: efidebug: Add missing \n at the end of message

Currently message is not intended that prompt end up at the end of debug
line. For example like this:

DFU alt info setting: done
DFU entities configuration failed!
(partition table does not match dfu_alt_info?)
Firmware update failed: <NULL>
Cannot handle a capsule at 10000000Zynq>

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4cd1fca3 21-Mar-2022 Masami Hiramatsu <masami.hiramatsu@linaro.org>

cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command
when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option
is available only when the EFI capsule update on disk is enabled.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ccc41fcf 23-Mar-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify do_efi_boot_add()

When calling efi_dp_from_name() we are not interested in the device part.
Just pass NULL as an argument.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 63276a56 25-Feb-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use short-form DP for load options

The GUID of partitions is sufficient for identification and will stay
constant in the lifetime of a boot option. The preceding path of the
device-path may change due to changes in the enumeration of devices.
Therefore it is preferable to use the short-form of device-paths in load
options. Adjust the 'efidebug boot add' command accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 156ccbc3 23-Jan-2022 Simon Glass <sjg@chromium.org>

efi: Use 16-bit unicode strings

At present we use wide characters for unicode but this is not necessary.
Change the code to use the 'u' literal instead. This helps to fix build
warnings for sandbox on rpi.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 3adae642 16-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify printing GUIDs

Use "%pS" to print text representations of GUIDs.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9ad37fe4 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: avoid multiple local copies of lf2_initrd_guid

Create the GUID as a global variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 05345425 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() unused parameter size

Parameter size is never used in function efi_dp_from_lo(). Remove it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# fc42b8bb 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

Use printf code %pD for printing device paths.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0421735d 14-Oct-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efi_dp_from_lo() don't copy GUID

Instead of copying a GUID and then using a pointer to the copy for calling
guidcmp(), just pass the pointer to the orginal GUID.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 2b8723c5 11-Jun-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efidebug: correct display of BootOrder

Display the number of the boot option and not its index.

Fixes: 2ecee31017bf ("efi_loader: use efi_create_indexed_name()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# acfe1def 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify accessing variables

Use efi_get_variable_int() instead of EFI_CALL(RT->get_variable()).
Use efi_set_variable_int() instead of EFI_CALL(efi_set_variable()).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 2ecee310 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: use efi_create_indexed_name()

Simplify the creation of indexed variable names like 'Boot0000' by using
function efi_create_indexed_name().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 60177e0a 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_order()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# cd5a87e7 24-May-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify show_efi_boot_opt_data()

To print a UTF-16 string use %ls instead of converting string to UTF-8.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# d473063d 02-Apr-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: simplify efi_get_device_path_text()

Replace static function efi_get_device_handle_info() by a simplified
function efi_get_device_path_text() avoiding EFI_CALL().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# aa31a87d 11-Mar-2021 Jose Marinho <jose.marinho@arm.com>

cmd: efi: ESRT table debug print

This commit enables the ESRT printing from the u-boot shell by invoking:
- efidebug capsule esrt

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>
Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64a8aae1 02-Mar-2021 Jose Marinho <jose.marinho@arm.com>

efi: Add ESRT to the EFI system table

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>

# cbea241e 17-Mar-2021 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efidebug: add multiple device path instances on Boot####

The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# df7d89a6 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 64d809b4 07-Feb-2021 Simon Glass <sjg@chromium.org>

efi: Fix compiler warnings

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>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>

# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>

# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>

# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)

# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>

# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>

# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>

# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>

# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>

# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a2c3f1bc 26-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: add firmware management protocol GUID

Add missing GUID short text used in the efidebug tables and efidebug dh
sub-commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b9b0ea30 02-Feb-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: install UEFI System Partition GUID

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>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30f8222b 21-Jan-2021 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: always check return code from get_variable()

CID 316364 says:
> Null pointer dereferences (FORWARD_NULL)
> printf("Result total size: 0x%x\n", result->variable_total_size);
at do_efi_capsule_res().

The code is basically safe because a buffer for "result" is allocated
by malloc() and filled up by the second get_variable(), which fails any way
if the allocation has failed.

But the first (and second) get_variable() possibly returns an error other
than EFI_SUCCESS. We always need to check the return code from
get_variable() before accessing the data in "result".

While this change won't suppress CID 316364, the resulting code is much
safer.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ff2f532f 15-Jan-2021 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: make the UEFI boot manager configurable

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>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 94686f60 13-Dec-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_DT_FIXUP_PROTOCOL

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>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 74075952 30-Dec-2020 Sughosh Ganu <sughosh.ganu@linaro.org>

efidebug: capsule: Add a command to update capsule on disk

Add a efidebug subcommand to initiate a firmware update using the efi
firmware management protocol(fmp) set_image routine.

The firmware update can be initiated through

'efidebug capsule disk-update'

This would locate the efi capsule file on the efi system partition,
and call the platform's set_image fmp routine to initiate the firmware
update.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>


# 7f35cedf 16-Nov-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add "efidebug capsule" command

"efidebug capsule" is more or less a debugging utility.
efidebug capsule update: invoke UpdateCapsule against data on memory
efidebug capsule show: show a capsule header
efidebug capsule result: dump a capsule result variable

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 94e78200 30-Nov-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for TCG2 final events table

A previous commit is adding EFI_TCG2_PROTOCOL, which in it's eventlog
support registers an EFI configuration table.
Let's add the necessary GUID so 'efidebug table' command can display
table names properly.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 79693351 27-Sep-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug display RNG protocol

Add the Random Number Generator (RNG) protocol to the GUIDs that the
'efidebug dh' protocol can replace by a text.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bc78d22d 11-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd/efidebug: missing initialization of load_options

Variable load_options must be initialized to NULL to avoid a segmentation
fault when freeing the memory this variable points to.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0ad64007 07-Aug-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: set load options in boot manager

Up to now we used the value of the bootargs environment variable as load
options in the boot manager. This is not correct. The data has to be taken
from the Boot#### variable.

Let the boot manager copy the optional data of the EFI_LOAD_OPTION as load
options to the loaded image protocol.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0e69bcfb 31-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: validate load option

For passing the optional data of the load option to the loaded imaged
protocol we need its size.

efi_deserialize_load_option() is changed to return the size of the optional
data.

As a by-product we get a partial validation of the load option.
Checking the length of the device path remains to be implemented.

Some Coverity defects identified the load options as user input because
get_unaligned_le32() and get_unaligned_le16() is called. But non of these
Coverity defects can be resolved without marking functions with Coverity
specific tags.

Reported-by: Coverity (CID 303760)
Reported-by: Coverity (CID 303768)
Reported-by: Coverity (CID 303776)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 255a4733 18-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: add EFI_MEMORY_SP to memory attributes

The UEFI 2.8 specification has introduced the EFI_MEMORY_SP memory
attribute. Add it to the 'efidebug memmap' and 'efi mem' commands.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 09140113 10-May-2020 Simon Glass <sjg@chromium.org>

command: Remove the cmd_tbl_t typedef

We should not use typedefs in U-Boot. They cannot be used as forward
declarations which means that header files must include the full header to
access them.

Drop the typedef and rename the struct to remove the _s suffix which is
now not useful.

This requires quite a few header-file additions.

Signed-off-by: Simon Glass <sjg@chromium.org>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b0e4f2c7 17-May-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

cmd: efidebug: Add support for querying UEFI variable storage

With the previous patches that use OP-TEE and StandAloneMM for UEFI
variable storage we've added functionality for efi_query_variable_info.
So let's add the relevant command to efidebug and retrieve information
about the container used to store UEFI variables

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# bdb15776 09-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix -Werror=type-limits warning

Compiling with -Wtype-limits yields:

cmd/efidebug.c:968:32: error: comparison is always false due to limited
range of data type [-Werror=type-limits]
968 | if (*endp != '\0' || bootnext > 0xffff) {
|

Remove the superfluous check.

Fixes: 59df7e7e77e7 ("cmd: add efidebug command")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e2a5b860 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add a comment against Coverity check (300329)

The check here, "Null pointer dereferences," is a false positive.
So leave a comment.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reported-by: Coverity (CID 300329)


# d67591dc 07-May-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a wrong handling of arguments

Coverity detected a dead code, but actually there is a bug in a check
against a number of arguments. So simply fix it.

Reported-by: Coverity (CID 300330)
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a30c7231 02-May-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify UEFI protocol calls

We should not to refer to a function via the run-time or boot services
tables if the function is exported.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f9f5f92b 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug bootorder'

* don't copy GUIDs for no reason
* shorten print format strings by using variable names
* don't use the run-time table to access exported functions
* check the result of malloc() (fixes Coverity CID 300331)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dd9056c0 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug, avoid illegal memory access

For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# b5f4e9e3 29-Apr-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: fix 'efidebug boot dump'

* Do not recreate a variable name that we already have as u16 string.
* Check the return value of malloc()
* EFI_NOT_FOUND cannot occur for a variable name returned by
GetNextVariableName(). Remove a print statement.
* Don't copy a GUID for no reason.
* Don't use the run-time service table to call exported functions.
* Don't pass NULL to show_efi_boot_opt_data() (fixes Coverity CID 300338).

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 525fc067 13-Apr-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add "test bootmgr" sub-command

This sub-command will be used to test image authentication,
in particular, a case where efi_load_image() failed with
EFI_SECURITY_VIOLATION but we still want to try efi_start_image().
We won't run such a case under normal bootmgr because it simply
refuses to call efi_start_image() if anything but EFI_SUCCESS
is returned when loading an image.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 6c0ef35c 26-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: fix int to pointer cast

On 32 bit systems fix
warning: cast to pointer from integer of different size
[-Wint-to-pointer-cast]

Fixes: a415d61eac26 ("cmd: map addresses to sysmem in efidebug memmap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a415d61e 14-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: map addresses to sysmem in efidebug memmap

Addresses in the sandbox's device tree are in the sandbox's virtual address
space. If we want to compare memory reservations in the device-tree with
the output of 'efidebug memmap', we need to convert back to this address
space.

Adjust the output of the 'efidebug memmap' command.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 30efb5dd 02-Mar-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: correct error message

Add the missing line feed at the error message if the variable referred to
by 'efidebug boot rm' does not exist.

Shorten the format string by using the variable name instead of the number
of the boot variable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e8bced62 27-Feb-2020 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a failure of "boot rm" sub-command

There is a wrong usage of utf8_utf16_strncpy() in "boot rm" command, and
then it will end up with a failure of this command due to a wrong
value of an interim variable ("var_name16").

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ec80b473 21-Feb-2020 Ilias Apalodimas <ilias.apalodimas@linaro.org>

efi_loader: Implement FileLoad2 for initramfs loading

Following kernel's proposal for an arch-agnostic initrd loading
mechanism [1] let's implement the U-boot counterpart.
This new approach has a number of advantages compared to what we did up
to now. The file is loaded into memory only when requested limiting the
area of TOCTOU attacks. Users will be allowed to place the initramfs
file on any u-boot accessible partition instead of just the ESP one.
Finally this is an attempt of a generic interface across architectures
in the linux kernel so it makes sense to support that.

The file location is intentionally only supported as a config option
argument(CONFIG_EFI_INITRD_FILESPEC), in an effort to enhance security.
Although U-boot is not responsible for verifying the integrity of the
initramfs, we can enhance the offered security by only accepting a
built-in option, which will be naturally verified by UEFI Secure Boot.
This can easily change in the future if needed and configure that via ENV
or UEFI variable.

[1] https://lore.kernel.org/linux-efi/20200207202637.GA3464906@rani.riverdale.lan/T/#m4a25eb33112fab7a22faa0fd65d4d663209af32f

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 76be6872 19-Feb-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: implement EFI_RT_PROPERTIES_TABLE

UEFI spec 2.8 errata A replaces the RuntimeServicesSupported variable
defined in UEFI spec 2.8 by the configuration table
EFI_RT_PROPERTIES_TABLE. So let's follow suit.

Cc: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Tested-by: Ard Biesheuvel <ardb@kernel.org>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 07e2fe79 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: capitalize UEFI

%s/uefi/UEFI/g

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 986e0648 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: new sub-command tables

Provide sub-command for efidebug to list configuration tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 173cd9e7 06-Jan-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

cmd: efidebug: simplify get_guid_text()

When we hit a matching GUID we can directly return the text. There is no
need for a check after the loop.

efi_guid_t is defined as 8 byte aligned but GUIDs in packed structures do
not follow this alignment. Do not require the argument of get_guid_text()
to be correctly aligned.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0bffb8c4 25-Nov-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: fix a build error in show_efi_boot_opt()

I detected the following error in sandbox with Clang on Travis CI:
+cmd/efidebug.c:703:15: error: result of comparison of constant
9223372036854775822 with expression of type 'int' is always false
[-Werror,-Wtautological-constant-out-of-range-compare]
+ else if (ret == EFI_NOT_FOUND)
+ ~~~ ^ ~~~~~~~~~~~~~

Simply changing a type of 'ret' to efi_status_t will fix this error.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# e7dcf564 01-Aug-2019 Simon Glass <sjg@chromium.org>

env: Drop environment.h header file where not needed

This header file is now only used by files that access internal
environment features. Drop it from various places where it is not needed.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Signed-off-by: Simon Glass <sjg@chromium.org>


# a6ccba0c 25-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: efidebug.c function documentation

make htmldocs produces a warning:
./cmd/efidebug.c:733: WARNING: Unexpected indentation.
Correct the indentation.

Remove 'See above for details of sub-commands.' which is not helpful in the
Sphinx generated documentation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 0b016569 14-Jul-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: function comments cmd/efi_debug.c

Adjust comments for Sphinx.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a332f251 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent error handling in efidebug.c

If a variable cannot be set, always show an information message.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 428a470a 19-Jun-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent types in efidebug.c

efi_status_t and int are of different size. Use separate variables for
return codes of different type.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# f658c2e1 04-Jun-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: make some boot variables non-volatile

Boot####, BootOrder and BootNext should be non-volatile.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 39a1ff8c 29-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: optional data in load options are binary

The field boot OptionalData in structure _EFI_LOAD_OPTIONS is for binary
data.

When we use `efidebug boot add` we should convert the 5th argument from
UTF-8 to UTF-16 before putting it into the BootXXXX variable.

When printing boot variables with `efidebug boot dump` we should support
the OptionalData being arbitrary binary data. So let's dump the data as
hexadecimal values.

Here is an example session protocol:

=> efidebug boot add 00a1 label1 scsi 0:1 doit1 'my option'
=> efidebug boot add 00a2 label2 scsi 0:1 doit2
=> efidebug boot dump
Boot00A0:
attributes: A-- (0x00000001)
label: label1
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit1
data:
00000000: 6d 00 79 00 20 00 6f 00 70 00 74 00 69 00 6f 00 m.y. .o.p.t.i.o.
00000010: 6e 00 00 00 n...
Boot00A1:
attributes: A-- (0x00000001)
label: label2
file_path: .../HD(1,MBR,0xeac4e18b,0x800,0x3fffe)/doit2
data:

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# ffe21574 25-Apr-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: rework "boot dump" sub-command using GetNextVariableName()

Currently in do_efi_boot_dump(), we directly read EFI variables from
related environment variables. To accommodate alternative storage
backends, we should switch to using the UEFI API instead.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 391bc8a9 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: more short texts for protocols in efidebug

The `efidebug dh` command shows handles and the installed protocols. For
most of the protocols implemented by U-Boot a short text was shown. But for
some only the GUID was displayed.

Provide the missing short texts for the following protocols: HII String,
HII Database, HII Config Routing, Simple Network, PXE Base Code.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# dec88e41 19-Apr-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: consistent naming of protocol GUIDs

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>


# 1fa442ed 28-Feb-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

efi_loader: error handling for `efidebug boot add`

In `efidebug boot add iPXE scsi 0:1 snp-arm64.efi --foo` a parameter is
missing. Hence the command should not silently return as if everything were
ok but should display the usage info.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Alexander Graf <agraf@csgraf.de>


# 00358bb8 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add memmap command

"memmap" command prints uefi-specific memory map information.
=> efi memmap
Type Start End Attributes
================ ================ ================ ==========
CONVENTIONAL 0000000040000000-000000007de27000 WB
RUNTIME DATA 000000007de27000-000000007de28000 WB|RT
RESERVED 000000007de28000-000000007de2a000 WB
RUNTIME DATA 000000007de2a000-000000007de2b000 WB|RT
RESERVED 000000007de2b000-000000007de2c000 WB
RUNTIME DATA 000000007de2c000-000000007de2d000 WB|RT
LOADER DATA 000000007de2d000-000000007ff37000 WB
RUNTIME CODE 000000007ff37000-000000007ff38000 WB|RT
LOADER DATA 000000007ff38000-0000000080000000 WB

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# fa536734 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add images command

"images" command prints loaded images-related information.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# a8014620 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add dh command

"dh" command prints all the uefi handles used in the system.

=> efi dh
7ef3bfa0: Device Path, Device Path To Text, Device Path Utilities,
Unicode Collation 2
7ef31d30: Driver Binding
7ef31da0: Simple Text Output
7ef31e10: Simple Text Input, Simple Text Input Ex
7ef3cca0: Block IO, Device Path
7ef3d070: Block IO, Device Path
7ef3d1b0: Block IO, Device Path, Simple File System
7ef3d3e0: Block IO, Device Path, Simple File System

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 66eaf566 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add drivers command

"drivers" command prints all the uefi drivers on the system.

=> efi drivers
Driver Name Image Path
================ ==================== ====================
000000007ef003d0 <NULL> <built-in>

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 355cdb5a 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: efidebug: add devices command

"devices" command prints all the uefi variables on the system.

=> efi devices
Scanning disk ahci_scsi.id0lun0...
Scanning disk ahci_scsi.id1lun0...
Found 4 disks
Device Device Path
================ ====================
000000007ef07ea0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)
000000007ef00c10 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)
000000007ef00dd0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)
000000007ef07be0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000)
000000007ef07510 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 59df7e7e 24-Feb-2019 AKASHI Takahiro <takahiro.akashi@linaro.org>

cmd: add efidebug command

Currently, there is no easy way to add or modify UEFI variables.
In particular, bootmgr supports BootOrder/BootXXXX variables, it is
quite hard to define them as u-boot variables because they are represented
in a complicated and encoded format.

The new command, efidebug, helps address these issues and give us
more friendly interfaces:
* efidebug boot add: add BootXXXX variable
* efidebug boot rm: remove BootXXXX variable
* efidebug boot dump: display all BootXXXX variables
* efidebug boot next: set BootNext variable
* efidebug boot order: set/display a boot order (BootOrder)

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>